//
//  BaseRequestEntity.m
//  BALPractice
//
//  Created by zhuhao on 15/3/5.
//  Copyright (c) 2015年 zhuhao. All rights reserved.
//

#import "BALBaseRequestEntity.h"
#import "NetworkHeader.h"
#import "BALRequestServiceManager.h"

@implementation BALBaseRequestEntity

-(instancetype)init{
    self = [super init];
    if (self) {
        
#ifdef Server_Test
       _baseURL = Server_Test_Host;
#endif
        
#ifdef Server_Simulation
        _baseURL = Server_Simulation_Host;
#endif
        
#ifdef Server_Real
        _baseURL = Server_Real_Host;
#endif
        _urlModulePath = nil;
        _timeout = kTimeoutInterval;
        _currentRequestOperation = nil;
        
        _params = [NSMutableDictionary dictionary];
        _requestMethod = RequestMethodTypeGet;
        
    }
    
    return self;
}

#pragma mark -
#pragma mark - public

-(void)formart{
    
    [_params removeAllObjects];
    
    //TODO: 添加公共参数
    [_params setObject:@"53d9dce22393c47196c7e5e6" forKey:@"appkey"];//TODO:确认:必选,其余可选
    [_params setObject:@"zh" forKey:@"locale"];
//    if (_user.isLogin)
//    {
//        [params c_safeSetObject:_user.userId forKey:@"userId"];
//        [params c_safeSetObject:_user.token forKey:@"token"];
//    }
    
    
    [_params setObject:@"ios" forKey:@"device"];
   
    [_params setObject:@"deviceid" forKey:@"deviceId"];
    [_params setObject:@"idphoto" forKey:@"appname"];
    [_params setObject:@"1.1" forKey:@"appversion"];
    [_params setObject:@"AppStore" forKey:@"channel"];
    [_params setObject:@"ios" forKey:@"platform"];
}

-(void)afterFormart{
    
}

-(void)startConnectServer{
    
    [self formart];
    
    [self afterFormart];
    
    [[BALRequestServiceManager shareServiceManager]requestWithEntity:self];
}

- (id)createDataModelWithResponseData:(id)responseData{
  NSLog(@"login -%@",responseData);
    return nil;
}

#pragma mark -
#pragma mark - private

- (void)addParam:(id<NSObject>)value forKey:(NSString *)key
{
    if (!value || value == [NSNull null] || !key || (id)key == [NSNull null])
    {
        return;
    }
    _params[key] = value;
}

#pragma mark -
#pragma mark - setter & getter

-(NSString *)urlPath{
    
    NSString *urlStr = [NSString stringWithFormat:@"%@/%@/",_baseURL,_urlModulePath];
    return urlStr;
}

@end
